package entities;

/**
 * keeps track of someone's financial situation ie. a student has a
 * FinancialInfo consists mostly of simple numerical data
 * 
 * @author gke703
 */
public class FinancialInfo {

	/** current annual personal income */
	private float personalIncome;

	/**
	 * current annual household income, should be greater than or equal to
	 * personalIncome
	 */
	private float householdIncome;

	/** current annual taxable earnings/income */
	private float taxableEarnings;

	/** current annual amount payed in child support */
	private float childSupport;

	/** total amount gained in scholarships/bursaries */
	private float scholarship;

	/** monthly expenses */
	private float monthlyExpenses;

	/**
	 * constructor, initializes attributes
	 */
	public FinancialInfo() {
		personalIncome = 0;
		householdIncome = 0;
		taxableEarnings = 0;
		childSupport = 0;
		scholarship = 0;
		monthlyExpenses = 0;
	}

	/**
	 * accessor for someone's personal income
	 * 
	 * @return float, peronal income
	 */
	public float getPersonalIncome() {
		return personalIncome;
	}

	/**
	 * mutator for someone's personal income
	 * 
	 * @param myIncome
	 *            , float, new personal income
	 * @throws RuntimeException
	 *             , if myIncome is negative
	 */
	public void setPersonalIncome(float myIncome) {
		if (myIncome < 0) {
			throw new RuntimeException("income must be a positive number");
		}

		personalIncome = myIncome;
	}

	/**
	 * accessor for someone's household income
	 * 
	 * @return float, household income
	 */
	public float getHouseholdIncome() {
		return householdIncome;
	}

	/**
	 * mutator for someone's household income
	 * 
	 * @param myIncome
	 *            , float, new household income
	 * @throws RuntimeException
	 *             , if myIncome is negative
	 */
	public void setHouseholdIncome(float myIncome) {
		if (myIncome < 0) {
			throw new RuntimeException("income must be a positive number");
		}

		householdIncome = myIncome;
	}

	/**
	 * accessor for someone's taxable income
	 * 
	 * @return float, taxable income
	 */
	public float getTaxableEarnings() {
		return taxableEarnings;
	}

	/**
	 * mutator for someone's taxable income
	 * 
	 * @param myIncome
	 *            , float, new taxable income
	 * @throws RuntimeException
	 *             , if myIncome is negative
	 */
	public void setTaxableEarnings(float myIncome) {
		if (myIncome < 0) {
			throw new RuntimeException("earnings must be a positive number");
		}

		taxableEarnings = myIncome;
	}

	/**
	 * accessor for someone's annual child support
	 * 
	 * @return float, child support
	 */
	public float getChildSupport() {
		return childSupport;
	}

	/**
	 * mutator for someone's annual owed child support
	 * 
	 * @param myIncome
	 *            , float, new child support
	 * @throws RuntimeException
	 *             , if myIncome is negative
	 */
	public void setChildSupport(float myIncome) {
		if (myIncome < 0) {
			throw new RuntimeException("earnings must be a positive number");
		}

		childSupport = myIncome;
	}

	/**
	 * accessor for someone's total gained scholarship amount
	 * 
	 * @return float, scholarship
	 */
	public float getScholarship() {
		return scholarship;
	}

	/**
	 * mutator for someone's annual gained total scholarship amount
	 * 
	 * @param myScholarship
	 *            , float, new scholarship
	 * @throws RuntimeException
	 *             , if myScholarship is negative
	 */
	public void setScholarship(float myScholarship) {
		if (myScholarship < 0) {
			throw new RuntimeException("earnings must be a positive number");
		}

		scholarship = myScholarship;
	}

	/**
	 * accessor for someone's monthly income
	 * 
	 * @return float, householdIncome/12
	 */
	public float getMonthlyIncome() {
		if (householdIncome != 0) {
			return householdIncome / 12;
		} else {
			return 0;
		}
	}

	/**
	 * accessor for someone's monthly expenses
	 * 
	 * @return float, monthlyExpenses
	 */
	public float getMonthlyExpenses() {
		return monthlyExpenses;
	}

	public void setMonthlyExpenses(float myExpenses) {
		if (myExpenses < 0) {
			throw new RuntimeException("expenses must be a postitive number");
		}

		monthlyExpenses = myExpenses;
	}

	/**
	 * regression tests
	 * 
	 * @param args
	 */
	public static void main(String[] args) {

		FinancialInfo myFinance = new FinancialInfo();

		if (myFinance.getPersonalIncome() != 0) {
			System.out.println("problem initializing personal income");
		}

		try {
			myFinance.setPersonalIncome(-9);
		} catch (RuntimeException e) {
			// System.out.println(e);
		}

		myFinance.setPersonalIncome(1000);
		if (myFinance.getPersonalIncome() != 1000) {
			System.out.println("problem changing personal income");
		}

		if (myFinance.getHouseholdIncome() != 0) {
			System.out.println("problem initializing household income");
		}

		try {
			myFinance.setHouseholdIncome(-67);
		} catch (RuntimeException e) {
			// System.out.println(e);
		}

		myFinance.setHouseholdIncome(3000);
		if (myFinance.getHouseholdIncome() != 3000) {
			System.out.println("problem changing household income");
		}

		if (myFinance.getTaxableEarnings() != 0) {
			System.out.println("problem initializing taxable income");
		}

		try {
			myFinance.setTaxableEarnings(-7);
		} catch (RuntimeException e) {
			// System.out.println(e);
		}

		myFinance.setTaxableEarnings(2000);
		if (myFinance.getTaxableEarnings() != 2000) {
			System.out.println("problem changing taxable income");
		}

		if (myFinance.getChildSupport() != 0) {
			System.out.println("problem initializing child support");
		}

		try {
			myFinance.setChildSupport(-100);
		} catch (RuntimeException e) {
			// System.out.println(e);
		}

		myFinance.setChildSupport(150);
		if (myFinance.getChildSupport() != 150) {
			System.out.println("problem changing child support");
		}

		if (myFinance.getScholarship() != 0) {
			System.out.println("problem initializing scholarship");
		}

		try {
			myFinance.setScholarship(-300);
		} catch (RuntimeException e) {
			// System.out.println(e);
		}

		myFinance.setScholarship(1500);
		if (myFinance.getScholarship() != 1500) {
			System.out.println("problem changing scholarship amount");
		}

		if (myFinance.getMonthlyIncome() != myFinance.getHouseholdIncome() / 12) {
			System.out.println("problem with monthly income");
		}

		try {
			myFinance.setMonthlyExpenses(-500);
		} catch (RuntimeException e) {
		}

		myFinance.setMonthlyExpenses(1000);
		if (myFinance.getMonthlyExpenses() != 1000) {
			System.out.println("problem with changing monthly expenses amount");
		}

	}

}
